package Song.Han.Demo01;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/*
    OutputStreamWriter:使用指定的charset将要写入流中的字符编码成字节

    构造方法：
        OutputStreamWriter(OutputStream out)：默认utf-8
        OutputStreamWriter(OutputStream out, String charsetName)：指定字符集charsetName，不区分大小写
*/
public class Demo01OutputStreamWriter {

    public static void main(String[] args) throws IOException {
        write_utf_8();
        write_gbk();
    }

    private static void write_gbk() throws IOException{
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("E:\\IDeaProject\\Day15\\src\\Song\\Han\\Demo01\\gbk.txt"),"gbk");

        osw.write("你好");
        osw.flush();
        osw.close();

    }

    private static void write_utf_8() throws IOException {

        //OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("E:\\IDeaProject\\Day15\\src\\Song\\Han\\Demo01\\utf_8.txt"),"utf-8");
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("E:\\IDeaProject\\Day15\\src\\Song\\Han\\Demo01\\utf_8.txt"));

        osw.write("你好");
        osw.flush();
        osw.close();
    }
}
